<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * FIXME: Description goes here ...
 *
 * @package RedCross
 * @category RedCross
 */
class RedCross_Form extends Zend_Form
{
    protected $_buttonElementDecorators = array(
		'ViewHelper',
        array('HtmlTag', array('tag' => 'li'))
    );

    protected $_elementDecorators = array(
        array('ViewHelper'),
        array('Errors'),
        array('Description'),
        array('Label'),
        array('HtmlTag', array('tag' => 'li'))
    );

    public function __construct($options = null)
    {
        $this->addElementPrefixPath('RedCross_Form_Decorator', 'RedCross/Form/Decorator', 'decorator');
        $this->addElementPrefixPath('RedCross_Filter', 'RedCross/Filter/', 'filter');
        $this->addElementPrefixPath('RedCross_Validate', 'RedCross/Validate/', 'validate');
        $this->addPrefixPath('RedCross_Form_Element', 'RedCross/Form/Element', 'element');

        $this->setDisableLoadDefaultDecorators(true);

        $this->clearDecorators();
        $this->addDecorator('FormElements')
            ->addDecorator('HtmlTag', array('tag' => 'ul'))
            ->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'class' => 'message_error'))
            ->addDecorator('Form');

        parent::__construct($options);

        $this->setMethod('post');
		$this->setAttrib('accept-charset', 'UTF-8');

        $this->setElementDecorators($this->_buttonElementDecorators, array('submit'), true);
        $this->addSecurity();
    }

//    protected function _getFormName()
//    {
//        $className = get_class($this);
//        $className = explode('_', $className);
//        $formName = array_pop($className);
//        $formGroup = array_pop($className);
//        $formGroup = $formGroup != 'Form' ? $formGroup : '';
//        return strtolower($formGroup . '_' . $formName);
//    }

    protected function addSecurity()
    {
//        $this->addElement('hash', 'csrf_hash_' . $this->_getFormName(), array('salt' => $this->createSalt()));
        $this->setElementFilters(array('StringTrim', 'HtmlPurifier'));
    }

//    private function createSalt()
//    {
//    	$salt = '';
//    	for ($i = 0; $i < 50; $i++) {
//            $salt .= chr(rand(33, 126));
//    	}
//    	return sha1($salt);
//    }
}
